package com.shen.accountbook.application;

import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.widget.Toast;

import com.shen.accountbook.BuildConfig;
import com.shen.accountbook.greendao.manager.DaoManager;
import com.shen.accountbook.utils.L;

import java.lang.reflect.Method;


/**
 * author:  shen
 * date:    2018/6/26
 *
 */
public class MyApp extends Application {

    DaoManager mDaoManager;

    private static Context mContext;
    private static MyApp instance;

    /** 是否联网 -- false:无联网; true:有联网 */
    private static boolean hasNetWork = false;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        instance = this;

//        CrashHandler crashHandler = CrashHandler.getInstance();
//		crashHandler.init(getApplicationContext());

        // mDaoManager = DaoManager.getInstance();
    }

    public static MyApp getInstance(){
        return instance;
    }

    public static Context getContext() {
        return mContext;
    }

    public static boolean isHasNetWork() {
        return hasNetWork;
    }

    public static void setHasNetWork(boolean hasNetWork) {
        MyApp.hasNetWork = hasNetWork;
    }


    /**
     * 显示在浏览器查看 手机数据库的IP
     */
    public static void showDebugDBAddressLog() {
        if (BuildConfig.DEBUG) {
            try {
                Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
                Method getAddressLog = debugDB.getMethod("getAddressLog");
                Object value = getAddressLog.invoke(null);
                L.i((String) value);
            } catch (Exception ignore) {

            }
        }
    }


    
    @Override
    public void onTerminate() {
        // 程序终止的时候执行
        L.i("MyApp", "onTerminate");

        super.onTerminate();
    }
    @Override
    public void onLowMemory() {
        // 低内存的时候执行
        L.i("MyApp", "onLowMemory");
        super.onLowMemory();
    }
    @Override
    public void onTrimMemory(int level) {
        // 程序在内存清理的时候执行（回收内存）
        L.i("MyApp", "onTrimMemory");// HOME键退出应用程序、长按MENU键，打开Recent TASK都会执行
        super.onTrimMemory(level);
    }
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        L.i("MyApp", "onConfigurationChanged");
        super.onConfigurationChanged(newConfig);
    }
}
